<!--代码逻辑和样式库-->
<script src="./device-list.component.js"></script>
<style src="./device-list.scss" scoped lang="scss"></style>

<template>
  <div>
    <!-- 搜索区域 -->
    <div class="search-container">
      <el-form label-position="top" :inline="true">
        <el-row type="flex">
          <el-col :span="24" class="aq-vertical-middle">
            <el-input v-if="codesCheck.indexOf('Query') !== -1" v-model="searchCriteria.queryStr" placeholder="请输入Serial No.或设备名称搜索" class="keyword" clearable @keyup.enter.native="search()"/>
            <el-select v-model="searchCriteria.isRelated" placeholder="请选择关联情况" clearable class="aq-margin-left-4">
              <el-option label="未关联" value="0"></el-option>
              <el-option label="已关联" value="1"></el-option>
            </el-select>
            <el-button v-waves v-if="codesCheck.indexOf('Query') !== -1" type="primary" icon="el-icon-search" class="aq-margin-left-8" @click="search()">
              查询
            </el-button>
            <el-button v-waves v-if="codesCheck.indexOf('Query') !== -1" type="warning" icon="el-icon-refresh" @click="reset()">
              重置
            </el-button>
            <el-button v-waves v-if="codesCheck.indexOf('Create') !== -1" type="success" icon="el-icon-edit" @click="openEditDialog('create')">
              新增
            </el-button>
            <el-button v-waves v-if="codesCheck.indexOf('Delete') !== -1" type="danger" icon="el-icon-delete" @click="cancelSelectedData()">
              取消关联车辆
            </el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 内容区域 -->
    <div class="content-container aq-margin-top-16">
      <!--用户角色table-->
      <el-table :data="data" border fit highlight-current-row @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" fixed></el-table-column>
        <el-table-column prop="serialNo" label="Serial No." />
        <el-table-column prop="equipmentName" label="设备名称" />
        <el-table-column prop="createTime" label="创建时间" width="160px" />
        <el-table-column prop="isRelated" label="是否关联车辆" width="70px">
          <template slot-scope="scope">
            {{ scope.row.isRelated == '1' ? '已关联' : '未关联' }}
          </template>
        </el-table-column>
        <el-table-column prop="licensePlate" label="车牌号码">
          <template slot-scope="scope">
            <el-link type="primary" @click="showCarDetailDialog(scope.row)">{{ scope.row.licensePlate }}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注信息" />
        <el-table-column prop="text" label="操作" width="240px" align="center" fixed="right">
          <template slot-scope="scope">
            <el-link v-if="codesCheck.indexOf('Edit') != -1" icon="el-icon-edit" type="primary" @click="openEditDialog('edit', scope.row)">编辑</el-link>
            <el-link class="aq-margin-left-16" icon="el-icon-connection" size="mini" type="success" @click="showCarDialog(scope.row)">关联车辆</el-link>
            <el-link class="aq-margin-left-16" v-if="codesCheck.indexOf('Delete') != -1" icon="el-icon-delete" size="mini" type="danger" @click="deleteSelectedData(scope.row.objectId)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页插件 -->
      <pagination v-show="totalNum > 0" :total="totalNum" :page.sync="pageNum" :limit.sync="recordNum" @pagination="getDataList" />
    </div>
    <!-- 创建/编辑角色 -->
    <el-dialog :title="dialogTitle" :visible.sync="editDialogVisible" width="500px">
      <el-form ref="dataForm" :model="editForm" :rules="editRules" label-position="left" label-width="100px">
        <el-row :gutter="20">
          <el-col :xs="24" :sm="24" :lg="24">
            <el-form-item prop="serialNo" label="Serial No.">
              <el-input v-model="editForm.serialNo" class="el-input-width" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24">
            <el-form-item prop="equipmentName" label="设备名称">
              <el-input v-model="editForm.equipmentName" class="el-input-width" clearable />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="24">
            <el-form-item label="设备备注">
              <el-input v-model="editForm.remark" type="textarea" :rows="3" class="el-input-width" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :sm="24" :lg="24" align="center">
            <el-button type="primary" class="action-btn" @click="save()">立即创建</el-button>
            <el-button class="action-btn" @click="editDialogVisible = false">取消</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!-- 显示关联车辆 -->
    <select-car v-if="showSelectCarDialog" :show-dialog.sync="showSelectCarDialog" :device-id="selectedData.objectId" @submit="setCar"></select-car>
    <!-- 显示车辆详情 -->
    <car-detail v-if="showSelectCarDetailDialog" :equip-id="equipId" :vehicle-id="vehicleId" :show-dialog.sync="showSelectCarDetailDialog"></car-detail>
  </div>
</template>
